package com.ashafa.fileutils;



import java.io.*;


import org.apache.log4j.*;



public class FetchFile {
	
	private static final Logger logger = Logger.getLogger(FetchFile.class.getName()); 
	
	public static String getString(String cononicalPath, String exceptionString){
		StringBuffer buffer = new StringBuffer();

		try
		{
			FileInputStream fis = new FileInputStream(cononicalPath);
			InputStreamReader isr = new InputStreamReader(fis);
			Reader in = new BufferedReader(isr);
			int ch;
			while ((ch = in.read()) > -1) {
			buffer.append((char)ch);
			}
			in.close();
			return buffer.toString();

		} catch(Exception e) {
			logger.warn(e.getMessage());
			return exceptionString;
		}
	}
	
public static String readFile(String filePath){
 		
	
	 return  readFile(filePath, "");
	 		
	
	}
	
	public static String readFile(String filePath, String exceptionString){
 		
		File file = null;
		try
 		{
			file= new File(filePath);
	 		
	 		return getString(file.getCanonicalPath(), exceptionString);
	 		
	
 		} catch(Exception e) {
 			logger.warn(e.getMessage());
 			return exceptionString;
 		}
	
		
	}
	
	
	

}
